﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data;

namespace DBManager.Admin
{
    public class BannersDAL
    {
        public static DataTable showAllBanner(string sSearch)
        {
            DataTable dt = new DataTable();
            string sql = "select *,case status when 1 then N'Dùng' when 0 then N'Không dùng' end as trangthai from banners where title like '%" + sSearch + "%' order by id desc";
            dt = DBUtil.SelectTable(sql);
            return dt;
        }
        public static DataTable getInfomationByID(string ID)
        {
            string sql = "select * from banners where id=" + comm.to_sqlnumber(ID);
            DataTable dt = new DataTable();
            dt = DBUtil.SelectTable(sql);
            return dt;
        }
        public static string editBanner(string title, string url, string shortContent, string img, string status, string sizeBanner, string catid, string note, string id)
        {
            string kq = "0";
            string sql = @"UPDATE Banners 
                           SET title = " + comm.to_sqltext(title) + @"
                          ,shortContent = " + comm.to_sqltext(shortContent) + @"
                          ,img = " + comm.to_sqltext(img) + @"
                          ,url = " + comm.to_sqltext(url) + @"
                          ,catID = " + comm.to_sqlnumber(catid) + @"
                          ,status = " + comm.to_sqlnumber(status) + @"
                          ,dateEdit = " + comm.to_sqltext(DateTime.Now.ToString("yyyyMMdd")) + @"
                          ,sizeBanner = " + comm.to_sqlnumber(sizeBanner) + @"
                          ,note = " + comm.to_sqltext(note) + @"
                           WHERE id= " + comm.to_sqlnumber(id);
            try
            {
                DBUtil.Execute(sql);
                kq = "1";
            }
            catch (Exception)
            {
                kq = "0";
            }
            return kq;
        }
        public static string addBanner(string title, string url, string shortContent, string img, string status, string sizeBanner, string catid, string note)
        {
            string kq = "0";
            string sql = @"INSERT INTO Banners 
           (title,url,shortContent,img,status,dateadded,dateEdit,sizeBanner,catID,note) 
            VALUES 
           (" + comm.to_sqltext(title) + @"
           ," + comm.to_sqltext(url) + @"
           ," + comm.to_sqltext(shortContent) + @"
           ," + comm.to_sqltext(img) + @"
           ," + comm.to_sqlnumber(status) + @"
           ," + comm.to_sqltext(DateTime.Now.ToString("yyyyMMdd")) + @"
           ," + comm.to_sqltext(DateTime.Now.ToString("yyyyMMdd")) + @"
           ," + comm.to_sqlnumber(sizeBanner) + @"
           ," + comm.to_sqlnumber(catid) + @"
           ," + comm.to_sqltext(note) + @")";
            try
            {
                DBUtil.Execute(sql);
                kq = "1";
            }
            catch (Exception)
            {
                kq = "0";
            }
            return kq;
        }
        public static DataTable getListBanner()
        {
            DataTable dt = new DataTable();
            string sql = "select * from ZoneBanner";
            dt = DBUtil.SelectTable(sql);
            return dt;
        }
    }
}
